var ConviteViewItemRender = new Class({
	"Extends":js.underas.controller.ListViewItemRender
	,"initialize":function(p_obj){						
		var htmlTmp = '<h4><span class="label label-info">'+p_obj.tempo+'</span> '+p_obj.tema+'</h4>';
		if(p_obj.nmMembro){
			htmlTmp += '<p class="list-group-item-text">'+p_obj.nmMembro.toUpperCase()+'</p>';	
		}
		htmlTmp += '<p class="list-group-item-text">data:'+p_obj.momento+'</p>'; 
		htmlTmp += '<p class="list-group-item-text">fonte:'+p_obj.fonte+'</p>'; 
		//htmlTmp += '<p class="list-group-item-text">'+p_obj.linkFonte+'</p>'; 
		this.parent('div',htmlTmp);
		this.getEle().addClass("col-xs-12 col-sm-4 col-md-4").setStyle("min-height","90px");
		}
	});

var Convite = new Class({
	"Extends":js.underas.container.ModWindow
	,"initialize":function(){
	    this.parent("*Lista de discursos por um periodo.");
		this.setRevision("$Revision: 138 $");	
		this.mainTb = new SimpleToolBar();
		 this.btPesquisar = new  Button("Pesquisar");
		    this.btPesquisar.addEvent('click',this.pesquisar.bind(this));
		    this.btPesquisar.setIcon("search");
		    
		    this.btLimpar = new  Button("Limpar");
		    this.btLimpar.addEvent('click',function(){
		    	convite.itDtaI.setValue("");
		    	convite.itDtaF.setValue("");
		    });
		    this.btLimpar.setIcon("remove");
		    
			this.btPrintSintetico = new js.underas.controller.Button("Discursos");
			this.btPrintSintetico.setIcon("print");
			this.btPrintSintetico.addEvent('click',this.printSintetico);
			
			this.btPrintConvites = new js.underas.controller.Button("Convites");
			this.btPrintConvites.setIcon("envelope");
			this.btPrintConvites.addEvent('click',this.printConvites);
			
		    
		    this.itDtaI = new  DatePicker();
		    this.itDtaI.setLabel("inicio:");
		    this.itDtaF = new js.underas.controller.DatePicker();
		    this.itDtaF.setLabel("fim:");
		    this.itDtaF.addDate("month",3);	       
			this.mainList = new js.underas.controller.ListView("convites");
			this.mainList.setItemRender("ConviteViewItemRender");
			this.setMainList("mainList");
			
			this.itLink = new js.underas.controller.AlertMsg("#");
			//this.itLink.setLabel("link:");
			this.itLink.setSize(12);
			//this.itLink.setEnable(false);
			
		   
		    this.mainTb.addButton(this.btPesquisar);
		    this.mainTb.addButton(this.btLimpar);
		    this.mainTb.addButton(this.btPrintSintetico);
		    this.mainTb.addButton(this.btPrintConvites);
		    
		    this.append(this.mainTb);
		    this.append(this.itDtaI);
		    this.append(this.itDtaF);
		    this.append(this.itLink);
		    this.append(this.mainList);
		}
		,"onChangeItem":function(p_item){		
			convite.itLink.setValue(p_item.linkFonte);		
		}	
		,"pesquisar":function(){
		    rm.addRequest({"puid":this.getVarModule(),"s":"discurso.business.DiscursoBLL.getByPeriodo","inicio":this.itDtaI.getValue(),"fim":this.itDtaF.getValue(),"onLoad":function(dta){
		    	//convite.getMainList().setDataProvider(dta.rs);
		    	convite.getMainList().setDataProvider([]).clear();		    	
				var tmpA = new ArrayList(dta.rs);
				var tm = tmpA.size();				
				var olddate = "";
				//usuario.historico.addRow(1,'<div class="amigodiv col-sm-12 col-sx-12" style="border:1px solid red"><div>');
				for(var i = 0;i<tm;i++){
					if(olddate!=tmpA.get(i).momento){	
						olddate=tmpA.get(i).momento;
						convite.getMainList().addRow(i,'<div class="convitedivfordate" style=""><h3 class="col-xs-12" style="text-align:center">'+olddate+'</h3></div>');
					}
					convite.getMainList().insertItem(tmpA.get(i),'bottom');
				}
				tmpA = null;
		    		    	
		    }});  
		}
		,"printSintetico":function(){
			_.printDataProvider(convite.getMainList().getDataProvider(),'assets/reports/convite_sintetico.json');
		}
		,"printConvites":function(){
			_.printDataProvider(convite.getMainList().getDataProvider(),'assets/reports/convites.json');
		}
	});